import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/clubs/club_news/club_news_controller.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/widget/dialog/club_message_dialog.dart';
import 'package:flutter_changdian_football/widget/dialog/message_dialog.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

/// 俱乐部消息
class ClubNewsPage extends StatelessWidget {
  const ClubNewsPage({super.key, this.clubId});

  final String? clubId;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        title: Text(
          '俱乐部消息',
          style: TextStyle(fontSize: 16.sp, color: const Color(0xff333333)),
        ),
        iconTheme: const IconThemeData(
          color: Color(0xff333333)
        ),
        backgroundColor: const Color(0xffF8FAF9 ),
      ),
      body: GetBuilder<ClubNewsController>(
        init: ClubNewsController(clubId: clubId),
        builder: (clubNewsController) {
          return RefreshWidget<ClubNewsController>(
            child: ListView.separated(
              itemCount: clubNewsController.checkMessageList.length,
              physics: const BouncingScrollPhysics(),
              separatorBuilder: (context, index) {
                return Container(
                  margin: EdgeInsets.only(left: 71.w),
                  width: double.infinity,
                  height: 1.w,
                  color: const Color(0xffF8FAF9),
                );
              },
              itemBuilder: (BuildContext context, int index) {
                return GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () {
                    ClubMessageDialog.show(
                      Get.context!, 
                      index: index,
                      confirmTap: () {
                        Get.back();
                      },
                      rejectTap: () {
                        clubNewsController.checkReject(index);
                      },
                      passTap: () {
                        clubNewsController.checkPass(index);
                      }
                    );
                  },
                  child: Container(
                    padding: EdgeInsets.symmetric(vertical: 15.w, horizontal: 17.w),
                    child: Row(
                      children: [
                        Stack(
                          children: [
                            Container(
                              width: 46.w,
                              height: 46.w,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(46.r)
                              ),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(46.r),
                                child: Image.network(clubNewsController.checkMessageList[index].userImg ?? '', fit: BoxFit.fill,),
                              ),
                            ),

                            if (clubNewsController.checkMessageList[index].status == 'WAIT_DEAL') ...[
                              Positioned(
                                right: 0.w,
                                child: Container(
                                  width: 16.w,
                                  height: 16.w,
                                  decoration: BoxDecoration(
                                    color: const Color(0xffF4333C),
                                    borderRadius: BorderRadius.circular(16.r)
                                  ),
                                  alignment: Alignment.center,
                                  child: Text('1', style: TextStyle(fontSize: 11.sp, color: Colors.white),),
                                )
                              )
                            ]
                            
                          ],
                        ),
                
                        SizedBox(width: 8.w,),
                
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              SizedBox(
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(clubNewsController.checkMessageList[index].nickname ?? '', style: TextStyle(fontSize: 15.sp, color: const Color(0xff333333),), maxLines: 1, overflow: TextOverflow.ellipsis,),
                                    Text(clubNewsController.checkMessageList[index].messageTime ?? '', style: TextStyle(fontSize: 11.sp, color: const Color(0xffcccccc),), maxLines: 1, overflow: TextOverflow.ellipsis,)
                                  ],
                                ),
                              ),
                
                              SizedBox(height: 4.w,),
                
                              SizedBox(
                                child: Text(clubNewsController.checkMessageList[index].message ?? '', style: TextStyle(fontSize: 12.sp, color: const Color(0xffCCCCCC),), maxLines: 1, overflow: TextOverflow.ellipsis,),
                              )
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                );
              },
            ),
          );
        }
      ),
    );
  }
}